热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

商品信息|都会_淘淘商城8.6

篇首语:本文由编程笔记#小编为大家整理,主要介绍了淘淘商城---8.6相关的知识,希望对你有一定的参考价值。继续八月五号写的,今天晚上花点时间开发这个项目&

篇首语:本文由编程笔记#小编为大家整理,主要介绍了淘淘商城---8.6相关的知识,希望对你有一定的参考价值。


继续八月五号写的,今天晚上花点时间开发这个项目,过程如下:


1、测试Maven工程

1.1、创建欢迎页

在webapp下创建一个index.jsp的欢迎页

index.jsp:


<%&#64; page language&#61;"java" contentType&#61;"text/html; charset&#61;UTF-8"
pageEncoding&#61;"UTF-8"%>








如果你看到此页面&#xff0c;说明taotao-manager已经运行







1.2、要运行的工程


要运行工程&#xff0c;需要运行聚合工程也就是taotao-manager。





1.3、配置Tomcat插件


在taotao-manager工程的pom文件中添加如下内容&#xff1a;





org.apache.tomcat.maven
tomcat7-maven-plugin

8080
/





1.4、启动工程



在浏览器上输入http://localhost:8080/


注意&#xff1a;

如果运行将taotao-manager运行在tomcat出错&#xff0c;执行下面两步&#xff1a;

1、需要把taotao-parent工程安装到本地仓库。Install

2、需要把taotao-common安装到本地仓库。install



2、创建数据库

使用mysql数据库。这里我提供数据库脚本taotao.sql,下载地址&#xff1a;http://pan.baidu.com/s/1kUMO4SJ


我这里是在CentOS7上搭建数据库系统&#xff0c;详情可以参考我的另一篇博客&#xff1a;CentOS7上安装mysql&#xff0c;链接地址&#xff1a;http://blog.csdn.net/sinat_31726559/article/details/51955125

然后用nativeCat连接上远程数据库&#xff0c;在mysql里面新建一个taotao的数据库&#xff0c;右键运行sql文件&#xff0c;将taotao.sql文件运行在taotao的数据库中&#xff0c;显示成功后就会导入项目中我们要用到的所有表。


注意&#xff1a;在互联网行业的项目中尽可能的减少表的管理查询。使用冗余解决表的关联问题。有利于分库分表。

商品表&#xff1a;




Sku&#xff1a;最小库存量单位。就是商品id。就是商品最细力度的划分。每个sku都唯一对应一款商品&#xff0c;商品的颜色、配置都已经唯一确定。


3、逆向工程

Mybatis的逆向工程。根据数据库表生成java代码。详细教程可参考:http://www.tuicool.com/articles/ABbqqie

这里我给大家提供好我这边能跑的官网工程&#xff0c;上面的配置文件是按照我机器上面的信息配置的&#xff0c;你们用的时候要记得将上面的一部分信息修改成符合你机器,逆向工程下载地址我已经上传到我的云盘里&#xff0c;链接是&#xff1a;http://pan.baidu.com/s/1qYvknrm


3.1、导入工程





3.2、修改generatorConfi.xml

generatorConfig.xml&#xff1a;



PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">







connectionURL&#61;"jdbc:mysql://192.168.43.163:3306/taotao" userId&#61;"root"
password&#61;"115010">







targetProject&#61;".\\src">






targetProject&#61;".\\src">




targetPackage&#61;"com.taotao.mapper" targetProject&#61;".\\src">



















3.3、运行逆向工程


运行成功后会产生上面两个java包下的代码。


4、SSM框架整合

4.1、整合思路


4.1.1、Dao层


使用mybatis框架。创建SqlMapConfig.xml。

创建一个applicationContext-dao.xml

1、配置数据源

2、需要让spring容器管理SqlsessionFactory&#xff0c;单例存在。

3、把mapper的代理对象放到spring容器中。使用扫描包的方式加载mapper的代理对象。


4.1.2、Service层


1、事务管理

2、需要把service实现类对象放到spring容器中管理。


4.1.3、表现层


1、配置注解驱动

2、配置视图解析器

3、需要扫描controller


4.1.4、Web.xml


1、spring容器的配置

2、Springmvc前端控制器的配置

3、Post乱码过滤器

4.2、框架整合


  首先思考我们这些配置文件应该放在我们创建的哪个工程下&#xff1f;

  答&#xff1a;就我思考&#xff0c;首先我们应该理解配置文件是干什么用的&#xff0c;假如我将配置文件放在taotao-manager-pojo下&#xff0c;他是一个jar形式的工程&#xff0c;开发完后会打包成jar放到lib下&#xff0c;这样程序就读不到配置文件了&#xff0c;所以这里我们应该放到war的工程下。


 

需要把配置文件放到taotao-manager-web工程下。因为此工程为war工程&#xff0c;其他的工程只是一个jar包。


4.2.1、mybatis整合

整合后的工程结构图如下所示&#xff1a;



SqlMapConfig.xml



PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">






applicationContext-dao.xml




xmlns:context&#61;"http://www.springframework.org/schema/context" xmlns:p&#61;"http://www.springframework.org/schema/p"
xmlns:aop&#61;"http://www.springframework.org/schema/aop" xmlns:tx&#61;"http://www.springframework.org/schema/tx"
xmlns:xsi&#61;"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation&#61;"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">




destroy-method&#61;"close">



















4.2.2、Service层



applicationContext-service.xml




xmlns:context&#61;"http://www.springframework.org/schema/context" xmlns:p&#61;"http://www.springframework.org/schema/p"
xmlns:aop&#61;"http://www.springframework.org/schema/aop" xmlns:tx&#61;"http://www.springframework.org/schema/tx"
xmlns:xsi&#61;"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation&#61;"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">







applicationContext-trans.xml




xmlns:context&#61;"http://www.springframework.org/schema/context" xmlns:p&#61;"http://www.springframework.org/schema/p"
xmlns:aop&#61;"http://www.springframework.org/schema/aop" xmlns:tx&#61;"http://www.springframework.org/schema/tx"
xmlns:xsi&#61;"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation&#61;"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

class&#61;"org.springframework.jdbc.datasource.DataSourceTransactionManager">




















pointcut&#61;"execution(* com.taotao.service.*.*(..))" />




4.2.3、表现层


springmvc.xml



xmlns:xsi&#61;"http://www.w3.org/2001/XMLSchema-instance" xmlns:p&#61;"http://www.springframework.org/schema/p"
xmlns:context&#61;"http://www.springframework.org/schema/context"
xmlns:mvc&#61;"http://www.springframework.org/schema/mvc"
xsi:schemaLocation&#61;"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


class&#61;"org.springframework.web.servlet.view.InternalResourceViewResolver">








web.xml



xmlns&#61;"http://java.sun.com/xml/ns/javaee" xmlns:web&#61;"http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation&#61;"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id&#61;"taotao" version&#61;"2.5">
taotao-manager

index.html
index.htm
index.jsp
default.html
default.htm
default.jsp



contextConfigLocation
classpath:spring/applicationContext-*.xml


org.springframework.web.context.ContextLoaderListener



CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter

encoding
utf-8



CharacterEncodingFilter
/*



taotao-manager
org.springframework.web.servlet.DispatcherServlet


contextConfigLocation
classpath:spring/springmvc.xml

1


taotao-manager
/




注意&#xff1a;标红部分的"/"会拦截所有请求包括静态资源。需要在springmvc.xml中添加静态资源的映射。

修改完的springmvc如下&#xff1a;



xmlns:xsi&#61;"http://www.w3.org/2001/XMLSchema-instance" xmlns:p&#61;"http://www.springframework.org/schema/p"
xmlns:context&#61;"http://www.springframework.org/schema/context"
xmlns:mvc&#61;"http://www.springframework.org/schema/mvc"
xsi:schemaLocation&#61;"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


class&#61;"org.springframework.web.servlet.view.InternalResourceViewResolver">













4.2.4、添加后台管理的静态资源页面

这部分的资源我已经上传到云盘&#xff0c;下载链接是:http://pan.baidu.com/s/1qYIkRIO

将里面的静态资源复制粘贴到WEB-INF下面&#xff0c;如图&#xff1a;


4.3、整合讨论

这里我们考虑一下为啥不直接用全局扫描呢&#xff1f;

答&#xff1a;首先我们要理解springmvc和spring的父子容器关系&#xff0c;如下图所示&#xff1a;


例如&#xff1a;

在applicationContext-service中配置&#xff1a;



会扫描&#64;Controller&#64;Service&#64;Repository&#64;Compnent

Springmvc.Xml中不扫描。

结果&#xff1a;springmvc。不能提供服务&#xff0c;因为springmvc子容器中不扫描会没有controller对象

所以这里我们不能去配置全局扫描&#xff0c;会找不到对象的。




5、整合测试

5.1、测试需求

这里我们就做个根据商品id查询商品信息。


5.2、SQL语句


SELECT * from tb_item WHERE id&#61;536563

5.3、Dao层

使用逆向工程生成的mapper文件


5.4、Service层

接收商品id调用dao查询商品信息。返回商品pojo对象&#xff0c;代码如下&#xff1a;

定义一个ItemService接口&#xff1a;


package com.taotao.service;
import com.taotao.pojo.TbItem;
/**
*
* &#64;ClassName: ItemService
* &#64;Description: TODO(商品管理的itemService接口)
* &#64;author 汪本成
* &#64;date 2016年8月6日 下午10:31:12
*
*/
public interface ItemService

TbItem getItemById(long itemId);


设计一个ItemService的实现类

package com.taotao.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.taotao.mapper.TbItemMapper;
import com.taotao.pojo.TbItem;
import com.taotao.pojo.TbItemExample;
import com.taotao.pojo.TbItemExample.Criteria;
import com.taotao.service.ItemService;
/**
*
* &#64;ClassName: ItemServiceImpl
* &#64;Description: TODO(商品管理的ItemService)
* &#64;author 汪本成
* &#64;date 2016年8月6日 下午10:30:28
* &#64;version 1.0
*/
&#64;Service
public class ItemServiceImpl implements ItemService

&#64;Autowired
private TbItemMapper itemMapper;
&#64;Override
public TbItem getItemById(long itemId)
// TODO Auto-generated method stub

/**
* 1、根据主键查询
*
//TbItem item &#61; itemMapper.selectByPrimaryKey(itemId);

/**
* 2、根据条件进行查询
*/
//添加查询条件
TbItemExample example &#61; new TbItemExample();
Criteria criteria &#61; example.createCriteria();
criteria.andIdEqualTo(itemId);
//返回查询结果到List中
List list &#61; itemMapper.selectByExample(example);
//进行判断
if(null !&#61; list && list.size() > 0)
TbItem item &#61; list.get(0);
return item;

return null;



5.5、Controller层


接收页面请求商品id&#xff0c;调用service查询商品信息。直接返回一个json数据。需要使用&#64;ResponseBody注解。


package com.taotao.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.taotao.pojo.TbItem;
import com.taotao.service.ItemService;
/**
*
* &#64;ClassName: ItemController
* &#64;Description: TODO(调用ItemService查询商品信息)
* &#64;author 汪本成
* &#64;date 2016年8月6日 下午10:49:53
*
*/
&#64;Controller
public class ItemController
&#64;Autowired
private ItemService itemService;

&#64;RequestMapping("/item/itemId")
&#64;ResponseBody
public TbItem getItemById(&#64;PathVariable Long itemId)
TbItem tbItem &#61; itemService.getItemById(itemId);
return tbItem;




5.6、查询结果


启动taotao-manager之后&#xff0c;打开浏览器输入http://localhost:8080/item/536563,会报错&#xff0c;如下&#xff1a;


这个错误的解决也很简单

修改taotao-manager-mapper的pom文件&#xff0c;在文件中添加下面内容就好






src/main/java

**/*.properties
**/*.xml

false





修改完之后刷新页面&#xff0c;如下&#xff1a;

测试ok&#xff01;&#xff0c;明天继续&#xff0c;欢迎关注&#xff0c;一直分享干货中。











推荐阅读
  • 移动端常用单位——rem的使用方法和注意事项
    本文介绍了移动端常用的单位rem的使用方法和注意事项,包括px、%、em、vw、vh等其他常用单位的比较。同时还介绍了如何通过JS获取视口宽度并动态调整rem的值,以适应不同设备的屏幕大小。此外,还提到了rem目前在移动端的主流地位。 ... [详细]
  • SpringMVC接收请求参数的方式总结
    本文总结了在SpringMVC开发中处理控制器参数的各种方式,包括处理使用@RequestParam注解的参数、MultipartFile类型参数和Simple类型参数的RequestParamMethodArgumentResolver,处理@RequestBody注解的参数的RequestResponseBodyMethodProcessor,以及PathVariableMapMethodArgumentResol等子类。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 本文介绍了Web学习历程记录中关于Tomcat的基本概念和配置。首先解释了Web静态Web资源和动态Web资源的概念,以及C/S架构和B/S架构的区别。然后介绍了常见的Web服务器,包括Weblogic、WebSphere和Tomcat。接着详细讲解了Tomcat的虚拟主机、web应用和虚拟路径映射的概念和配置过程。最后简要介绍了http协议的作用。本文内容详实,适合初学者了解Tomcat的基础知识。 ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • springmvc学习笔记(十):控制器业务方法中通过注解实现封装Javabean接收表单提交的数据
    本文介绍了在springmvc学习笔记系列的第十篇中,控制器的业务方法中如何通过注解实现封装Javabean来接收表单提交的数据。同时还讨论了当有多个注册表单且字段完全相同时,如何将其交给同一个控制器处理。 ... [详细]
  • 标题: ... [详细]
  • 本文介绍了南邮ctf-web的writeup,包括签到题和md5 collision。在CTF比赛和渗透测试中,可以通过查看源代码、代码注释、页面隐藏元素、超链接和HTTP响应头部来寻找flag或提示信息。利用PHP弱类型,可以发现md5('QNKCDZO')='0e830400451993494058024219903391'和md5('240610708')='0e462097431906509019562988736854'。 ... [详细]
  • 本文介绍了如何使用C#制作Java+Mysql+Tomcat环境安装程序,实现一键式安装。通过将JDK、Mysql、Tomcat三者制作成一个安装包,解决了客户在安装软件时的复杂配置和繁琐问题,便于管理软件版本和系统集成。具体步骤包括配置JDK环境变量和安装Mysql服务,其中使用了MySQL Server 5.5社区版和my.ini文件。安装方法为通过命令行将目录转到mysql的bin目录下,执行mysqld --install MySQL5命令。 ... [详细]
  • 如何在HTML中获取鼠标的当前位置
    本文介绍了在HTML中获取鼠标当前位置的三种方法,分别是相对于屏幕的位置、相对于窗口的位置以及考虑了页面滚动因素的位置。通过这些方法可以准确获取鼠标的坐标信息。 ... [详细]
  • 本文介绍了一种在PHP中对二维数组根据某个字段进行排序的方法,以年龄字段为例,按照倒序的方式进行排序,并给出了具体的代码实现。 ... [详细]
  • JS实现一键分享功能
    本文介绍了如何使用JS实现一键分享功能,并提供了2019独角兽企业招聘Python工程师的标准。同时,给出了分享到QQ空间、新浪微博和人人网的链接。 ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
author-avatar
mobiledu2502934511
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有